function Undefend takes nothing returns nothing
	local trigger undefendTrigger = GetTriggeringTrigger()
	local integer undefendTriggerId = GetHandleId(undefendTrigger)
	local triggeraction undefendTriggerAction = null
	//--
	if GetIssuedOrderId() == OrderId("undefend") then
		call ModifyUnitDefendPercent(GetTriggerUnit() , -30.0)
		set undefendTriggerAction = LoadTriggerActionHandle(udg_TriggerHashTable , undefendTriggerId , 5)
		call FlushChildHashtable(udg_TriggerHashTable , undefendTriggerId)
		call TriggerRemoveAction(undefendTrigger , undefendTriggerAction)
		call DestroyTrigger(undefendTrigger)
	endif
	//--
	set undefendTrigger = null
	set undefendTriggerAction = null
endfunction

function Trig_Defend_Actions takes nothing returns nothing
	local unit defendUnit = GetTriggerUnit()
	local trigger undefendTrigger = CreateTrigger()
	local integer undefendTriggerId = GetHandleId(undefendTrigger)
	local triggeraction undefendTriggerAction = null
	//--
	call ModifyUnitDefendPercent(defendUnit , 30.0)
	
	call DisableTrigger(undefendTrigger)
	call TriggerRegisterUnitEvent(undefendTrigger , defendUnit , EVENT_UNIT_ISSUED_ORDER)
	set undefendTriggerAction = TriggerAddAction(undefendTrigger , function Undefend)
	call SaveTriggerActionHandle(udg_TriggerHashTable , undefendTriggerId , 5 , undefendTriggerAction)
	call EnableTrigger(undefendTrigger)
	//--
	set defendUnit = null
	set undefendTrigger = null
	set undefendTriggerAction = null
endfunction

function Trig_Defend_Conditions takes nothing returns boolean
	return GetIssuedOrderId() == OrderId("defend")
endfunction

function InitTrig_Defend takes nothing returns nothing
	set gg_trg_Defend = CreateTrigger()
	call TriggerRegisterPlayerForceUnitEvent(gg_trg_Defend , EVENT_PLAYER_UNIT_ISSUED_ORDER)
	call TriggerAddCondition(gg_trg_Defend , Condition(function Trig_Defend_Conditions))
	call TriggerAddAction(gg_trg_Defend , function Trig_Defend_Actions)
endfunction

